package com.wangbo.box.proxy;


/**
 * 静态代理模式
 */
public class StaticProxyPattern {

    interface Subject{
        void invoke();
    }

    static class RealSubject implements Subject{

        @Override
        public void invoke() {
            System.out.println("this is realSubject invoke");
        }
    }

    static class Proxy implements Subject{

        RealSubject realSubject;

        Proxy(RealSubject realSubject) {
            this.realSubject = realSubject;
        }

        @Override
        public void invoke() {
            if (realSubject == null){
                realSubject = new RealSubject();
            }
            System.out.println("pre invoke");
            realSubject.invoke();
            System.out.println("post invoke");
        }
    }

    public static void main(String[] args) {
        Proxy proxy = new Proxy(null);
        proxy.invoke();
    }
}
